const refreshInterval = 3000 // 限制间隔，单位毫秒

window.addEventListener('keydown', (event) => {
  if (event.key === 'F5' || event.keyCode === 116) {
    event.preventDefault() // 阻止默认刷新行为
    let lastRefreshTime = localStorage.getItem('lastRefreshTime') ?? 0

    const currentTime = new Date().getTime() // 获取当前时间
    if (currentTime - lastRefreshTime > refreshInterval) {
      lastRefreshTime = currentTime // 更新刷新时间
      localStorage.setItem('lastRefreshTime', lastRefreshTime)
      console.log('页面刷新了')

      window.location.reload() // 手动刷新页面
    } else {
      console.log('刷新过于频繁，请稍后再试！')
    }
  }
})
